home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Reference Guide / C-C++ Interactive Reference Guide.iso / c_ref / csource4 / 221_01 / cc.doc < prev    next >
Text File  |  1979-12-31  |  7KB  |  312 lines

  1.                      C Compiler Documentation
  2.  
  3.  
  4.  
  5. INTRODUCTION:
  6.  
  7. This compiler is the small C compiler written by Ron
  8. Cain and published in Dr. Dobb's #45 (May '80). The compiler
  9. was modified for the 6809 CPU and also enhanced by 
  10. Dieter H. Flunkert.  Some help was taken from J. E. Hendrix's
  11. version of the small C compiler and articles from DDJ.
  12.  
  13. This compiler accepts a subset of standard C. 
  14.  
  15.  
  16.  
  17. DATA TYPES:
  18.  
  19. The data types are...
  20.  
  21. char c  character 
  22. char *c  pointer to character 
  23. char c[n]; character array 
  24. int i;  16 bit integer 
  25. int *i;  pointer to integer 
  26. int i(); function returning integer 
  27. int i[n]; integer array 
  28.  
  29.  
  30.  
  31. STORAGE CLASSES:
  32.  
  33. automatic:  This class is the default.  It is possible to
  34.             specify it explicit, but the preprocessor will
  35.             strip it out (it is #define automatic).
  36. static:     Supported!
  37. register:   This class is also only known by the preprossesor
  38.             who strips it out.
  39. extern:     Supported!
  40. typedef:    Not supported.
  41.  
  42.  
  43.  
  44. Structures, multidimensional arrays, unions,
  45. and more complex types like "int **i" are not included.
  46.  
  47.  
  48.  
  49.  
  50. PRIMARIES:
  51.  
  52.  array[expression] 
  53.  function(arg1,arg2,...,argn) 
  54.  constant 
  55.   decimal integer 
  56.   quoted string    ("sample string") 
  57.   primed character ('a'  or  'Z')
  58.   also literals like '\n', '\b' etc. 
  59.  local variable 
  60.  global variable 
  61.  
  62. Each variable must be declared before it is used.
  63.  
  64.   
  65.  
  66.  
  67. UNARY INTEGER OPERATORS:
  68.  
  69.  - minus 
  70.  * indirection (points to object)
  71.  & address of 
  72.  ++ increment, either prefix or suffix 
  73.  -- decrement, either prefix or suffix 
  74.  ~  complement
  75.  !  not
  76.   
  77.  
  78.  
  79.  
  80. BINARY INTEGER OPERATORS:
  81.  
  82.  + addition 
  83.  - subtraction 
  84.  * multiplication 
  85.  / division 
  86.  % mod, remainder from division 
  87.  | inclusive or 
  88.  ^ exclusive or 
  89.  & logical and 
  90.  == equal 
  91.  != not equal 
  92.  < less than 
  93.  <= less than or equal 
  94.  > greater than 
  95.  >= greater than or equal 
  96.  << left shift 
  97.  >> arithmetic right shift 
  98.  
  99.  
  100.  
  101. LOGICAL OPERATORS:
  102.  
  103.  && logical and operator
  104.  || logical or operator
  105.  
  106.  
  107.  
  108.  
  109. CONDITIONAL OPERATOR:
  110.  
  111.  ?: Supported
  112.  
  113.  
  114.  
  115.  
  116. ASSIGNMENT OPERATORS:
  117.  
  118.  lvalue = expression
  119.  lvalue += expression
  120.  lvalue -= expression
  121.  lvalue *= expression
  122.  lvalue /= expression
  123.  lvalue %= expression
  124.  lvalue >>= expression
  125.  lvalue <<= expression
  126.  lvalue &= expression
  127.  lvalue ^= expression
  128.  lvalue |= expression
  129.  
  130.  
  131.  
  132. COMMA OPERATOR:
  133.  
  134.  supported!
  135.  
  136.  
  137.  
  138.  
  139. PROGRAM CONTROL
  140.  
  141.  if(expression) statement; 
  142.  if(expression) statement; else statement; 
  143.  while(expression) statement; 
  144.  do statement; while(expression);
  145.  for(expression_1;expression_2;expression_3) statement;
  146.    (where the expressions _1,_2,_3 are optional)
  147.  switch(expression) statement;
  148.  case constant-expression : expression;
  149.  default: expression;
  150.  break; 
  151.  continue; 
  152.  return;
  153.  return expression; 
  154.  ;        /* null statement */
  155.  {statement;statement;   ...   statement;}
  156.      /* compound statement */ 
  157.    
  158.  
  159.  
  160. not included: goto and labels.
  161.  
  162.  
  163.  
  164. INITIALIZATION:
  165.  
  166.  Global and static variables are per default initialized
  167.  with zero.  It is possible to give this variables a init
  168.  value.
  169.  
  170.  For example:     char c = 'a'   /* c has now the value of 'a' */
  171.                   int i = 1;     /* i contains now the value 1 */
  172.  
  173.                   char c[80] = "this is a string";
  174.                                  /* the array of characters are
  175.                                     inityialized with the text and
  176.                                     the rest of the array is zero */
  177.  
  178.       int i[10] = 1,2,3;
  179.                                  /* i[0] = 1
  180.                                     i[1] = 2
  181.                                     i[2] = 3
  182.                                     the rest will be zero */
  183.  
  184.                   int i[] = 1,2,3;
  185.                                  /* same as above, but the length of
  186.                                     the array will be 4
  187.                                     it is the same as: 
  188.                                                 int i[4] = 1,2,3,0 */
  189.  
  190.   All mentioned above is also valid for static variables.
  191.  
  192.  
  193.  
  194.  
  195.  
  196. EMBEDDED COMPILER COMMANDS:
  197.  
  198.  #define name [string]
  199.  
  200. "name" is replaced by "string" hereafter. If no "string" is given
  201. only the MACRO name is defined (usefull for conditional compile).
  202.  
  203.    #ifdef name
  204.  
  205. checks whether the name is currently defined in the preprocessor;
  206. that is, whether it has been defined with #define name.  A control
  207. line of the form
  208.  
  209.    #ifndef name
  210.  
  211. checks whether the identifier is currently undefined in the pre-
  212. processor.
  213.   All forms are followed by an arbitrary number of lines, possibly
  214. containing a control line
  215.  
  216.    #else
  217.  
  218. and the by a control line
  219.  
  220.    #endif
  221.  
  222.  
  223.  
  224.  #include filename 
  225.  
  226. compiler gets source code from another file (can't be nested) 
  227.  
  228.  #asm 
  229.  ... 
  230.  ... 
  231.  #endasm 
  232.  
  233. code between these is passed directly to the assembler.  
  234.  
  235.  
  236.  
  237.  
  238. COMMAND LINE:
  239.  
  240. When the compiler is run, it reads one or more C source files
  241. and produces one assembly language file. The assembly language
  242. files are separately assembled by RELASMB, then are combined into
  243. a single executable file by LLOAD. The format of the compiler
  244. command line is:
  245.  
  246.  cc <input-file [>output_file] [options]  
  247. Each option is a minus sign followed by a letter:
  248.  
  249.  -C to include the C source code as comments in
  250.   the compiler-generated assembly code.
  251.  
  252.  -P pause after an error is encountered.
  253.  
  254.  -M monitor function header.
  255.  
  256.  -T trace function enabled.
  257.  
  258.  
  259.  
  260. LIBRARY FILES: 
  261.  
  262. CC.LIB  This is the small-C runtime library
  263.  
  264. If one of the runtime modules are used, the file STDIO.H 
  265. must be included (This means nearly always).
  266.  
  267.  
  268.  
  269. SAMPLE COMPILATION:
  270.  
  271.  +++cc <test.c >test.asm -m -c -p
  272.  
  273. This line causes the compile to compile the input file
  274. test.c and write the generated code withe the c-text
  275. interleaved to the output file test.asm.  The functions
  276. will be monitored and on error a question mark will
  277. appear on the screen.  Control C will abort the compile,
  278. any other character causes the compiler to continue.
  279. At compile end, a summary of error messages are shown.
  280.  
  281.  
  282.    +++RELASMB TEST.ASM +LSY
  283.  
  284. This command calls the relocatable assembler.  The file
  285. TEST.ASM will be assembled, no listing and no symbol
  286. table are generated.
  287.  
  288.    +++LLOAD CCROOT TEST +L=CC.LIB +A=0 +MYCO=TEST
  289.  
  290. This command invokes the linking loader which links the 
  291. program TEST.REL with the root module and the run time
  292. library.  The root module is essential.  The linking
  293. loader will create an absolute module with starting adr
  294. of 0 (+A=0).  The resulting program is named TEST.CMD
  295. and a linking map is displayed (+MYCO=TEST).
  296.  
  297.  
  298.  
  299.  
  300. OPTIMIZATION:
  301.  
  302.  The compiler will not produce an optimized code.  Therefore
  303.  I wrote a small peephole optimizer which reduces the compiler
  304.  output code by 15% to 20%.
  305.  
  306.  The optimizer is invoked by:
  307.  
  308.    PEEPHOLE <inputfile [>outputfile]
  309.  
  310.  If you omit the output file specification, the output will be
  311.  directed to the terminal.
  312.